package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class CancelOrderConfig {


    /**
     * 自定义延迟队列交换机
     */
    @Bean
    public CustomExchange cancelOrderExchange() {
        //设置参数
        Map<String,Object> args = new HashMap<>();
        args.put("x-order-type","direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-order-cancel-exchange",true,false,args);
    }

    /**
     * 延迟队列
     */
    @Bean
    public Queue dealyQueue() {
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    @Bean
    public Binding delayBinding() {
        return BindingBuilder.bind(dealyQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
